package com.yu.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

public class DBUtil {
	
	public static Connection conn = null;  
	
	public static Set<String> tmpproduct = null;
	
	public static Connection getConn(){
		if (conn == null){
			String user = "cmdev"; 
	    	String password = "ucarspeed@314159"; 
	    	String jdbcDriver = "com.mysql.jdbc.Driver"; 
	    	String jdbcUrl = "jdbc:mysql://120.26.52.158:3306/cm_club?characterEncoding=UTF8&useUnicode=true&zeroDateTimeBehavior=convertToNull&connectionTimeout=30000&socketTimeout=30000"; 
	    	
	    	try {
				Class.forName(jdbcDriver);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
	    	try {
				conn = DriverManager.getConnection(jdbcUrl, user, password);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return conn;
	}
	
	public static void addtmp(String tmp){
		if (tmpproduct == null){
			tmpproduct = Sets.newHashSet(); 
		}
		tmpproduct.add(tmp);
		
	}
	public static void closeConn(){
		if (conn != null){
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
}
